﻿<?php
class Admin_ClientsController extends My_Controller_Admin_Choix
{
	protected $clientsModel = '';

	protected function _init()
	{
		$this->clientsModel = new Admin_Model_Clients();
	}

	public function indexAction()
	{
        $org = $this->_getParam('org', 'all');
        $ordre = $this->_getParam('ordre', 'num_client, nom');
        $tri = $this->_getParam('tri', 'asc');

	    $num_vente = $this->_getParam('num_vente');
		$rowPerPage = $this->_getParam('rowperpage', 20);
		$currentPage = 1;
		$page = $this->_getParam('page', 1);
		if(!empty($page)) {
			$currentPage = $page;
		}

        if ($org == "all" || $org == "arc")
		    $rows = $this->clientsModel->getListClient($num_vente, $org, $ordre, $tri);
        else
            $rows = $this->clientsModel->getListClientArchived($num_vente, $org, $ordre, $tri);

		$paginator = Zend_Paginator::factory($rows);
		$paginator->setItemCountPerPage($rowPerPage);
		$paginator->setCurrentPageNumber($currentPage);

		$this->view->page = $page;
		$this->view->paginator = $paginator;
        $this->view->org = $org;
        $this->view->ordre = $ordre;
        $this->view->tri = $tri;
		$this->view->num_vente = $num_vente;

	}

	public function addAction()
	{
		$this->_forward('edit');
	}

	public function editAction()
	{
		$num_vente = $this->_getParam('num_vente', 0);
        $org = $this->_getParam('org', 'all');
		$num = $this->_getParam('id', 0);
		$id = $this->_getParam('id', 0);
		$numVente = $this->_getParam('num_vente', 0);
		$client = array();
		$clientVente = array();
		if ($id) {
		    $client = $this->clientsModel->getClientById($id);
		    $clientVente = $this->clientsModel->getClientVentes($id, $numVente);
		}

		$this->view->num_vente = $num_vente;
		$this->view->org = $org;
		$this->view->num = $num;
		$this->view->messages = $this->_helper->flashMessenger->getMessages();
		$this->view->client = new My_Object($client);
		$this->view->clientVente = new My_Object($clientVente);
	}

	public function saveAction()
	{
	    $id = $this->_getParam('id', 0);
	    $numVente = $this->_getParam('num_vente', 0);
        $param = '/?num_vente=' . $numVente;
        $param .= $id ? '&id=' . $id : '';
	    $clientData = $this->_getParam('client');
	    $clientVenteData = $this->_getParam('vente');
	    if ($clientData['email']) {
	        $clientId = $this->clientsModel->validateEmail($clientData['email']);
	        if ($clientId && $clientId != $id) {
	            $flashMessenger = $this->getHelper('flashMessenger');
	            $flashMessenger->setNamespace('error')->addMessage('Cette adresse e-mail existe déjà dans la DB !');
	            $this->_redirect('admin/clients/edit' . $param);
	        }
	    }
	    if ($clientData['userid']) {
	        $clientId = $this->clientsModel->validateUserid($clientData['userid']);
	        if ($clientId && $clientId != $id) {
	            $flashMessenger = $this->getHelper('flashMessenger');
	            $flashMessenger->setNamespace('error')->addMessage('Ce userid existe déjà dans la DB !');
	            $this->_redirect('admin/clients/edit' . $param);
	        }
	    }
	    if (isset($clientData['archive'])) {
	        $this->clientsModel->updateNumClient($id, $numVente);
	        $clientVenteData['num_vlient'] = 'n';
	    } else {
	        $clientData['archive'] = 0;
	    }
	    if (!$clientVenteData['num_client']) {
	        $clientVenteData['num_client'] = 'n';
	    }
	    $checkboxField = array('vendeur', 'acheteur', 'contact', 'obj', 'fg', 'bd');
	    foreach ($checkboxField as $key) {
	        if (!isset($clientData[$key])) {
	            $clientData[$key] = 0;
	        }
	    }
	    $this->clientsModel->save($clientData, $id);
	    $this->_redirect('admin/clients/?num_vente=' . $numVente);
	    /*
	    if ($id) {
	        $this->_forward('update');
	    } else {
	        $this->_forward('insert');
	    }
	    */
	}

	public function insertClientsAction()
	{
		$num_vente = $this->_getParam('num_vente', 0);
		$num_client = $this->_getParam('num_client', 0);
        $org = $this->_getParam('org', 'all');

		$liste = "contact,vendeur,acheteur,identite,email,commission,prenom,nom,adresse,adresse2,cp,ville,pays,tel1,tel2,tel3,tel4,banque,tva,obj,bd,fg";
		// On stocke dans des variables de sessions les valeurs du formulaire pour le remplir dans la page précédente
		$i = explode(",",$liste);
		for ($compt=0; $compt<(count($i)); $compt++) {
			$_SESSION[$i[$compt]] = $_POST[$i[$compt]];
		}

		// On vérifie si le n° de client existe déjà dans la DB
		if (!$num_client) {
			$num_client = 'n';
		} else {
			$num_client = sprintf("%04s", $num_client);
		}

		if ($num_client != 'n') {
			$count = $this->clientsModel->isClient($num_client, $num_vente);
			if ($count != 0) {
				$mgs  = "Ce n° de client existe déjà !";
				$this->_helper->flashMessenger->addMessage($mgs);
				$this->_redirect('admin/clients/add?num_vente='. $num_vente .'&org='. $org);
			}
		}

		$vendeur = $this->_getParam('vendeur', 0);
		$acheteur = $this->_getParam('acheteur', 0);
		$contact = $this->_getParam('contact', 0);
		$nom = addslashes($this->_getParam('nom', ''));
		$co = addslashes($this->_getParam('co', ''));
		$prenom = addslashes($this->_getParam('prenom', ''));
		$adresse = addslashes($this->_getParam('adresse', ''));
		$adresse2 = addslashes($this->_getParam('adresse2', ''));
		$ville = addslashes($this->_getParam('ville', ''));
		$bd = $this->_getParam('bd', 0);
		$obj = $this->_getParam('obj', 0);
		$fg = $this->_getParam('fg', 0);
		$archive = $this->_getParam('archive', 0);

		$identite = $this->_getParam('identite', 0);
		$email = $this->_getParam('email', '');
		$pays = $this->_getParam('pays', '');
		$tel1 = $this->_getParam('tel1', '');
		$tel2 = $this->_getParam('tel2', '');
		$tel3 = $this->_getParam('tel3', '');
		$tel4 = $this->_getParam('tel4', '');
		$banque = $this->_getParam('banque', '');
		$tva = $this->_getParam('tva', '');
		$civilite = $this->_getParam('civilite', '');
		$catoffice = $this->_getParam('catoffice', '');
		$contact_depot = $this->_getParam('contact_depot', '');
		$commission = $this->_getParam('commission', '');
		$cp = $this->_getParam('cp', '');

		$cle = $this->clientsModel->getMaxClient();
		$data = array(
			p_clients		=> $cle,
			vendeur			=> $vendeur,
			acheteur		=> $acheteur,
			num_identite	=> $identite,
			email			=> $email,
			prenom			=> $prenom,
			nom				=> $nom,
			adresse			=> $adresse,
			adresse2		=> $adresse2,
			cp				=> $cp,
			ville			=> $ville,
			f_pays			=> $pays,
			tel1			=> $tel1,
			tel2			=> $tel2,
			tel3			=> $tel3,
			tel4			=> $tel4,
			compte_banque	=> $banque,
			tva				=> $tva,
			dtcreat			=> date('Y-m-d'),
			hrcreat			=> date('his'),
			co				=> $co,
			f_civilites		=> $civilite,
			contact			=> $contact,
			bd				=> $bd,
			obj				=> $obj,
			fg				=> $fg,
			archive			=> $archive,
			catoffice		=> $catoffice,
			contact_depot	=> $contact_depot
		);

		$clientsModel = new Admin_Model_Clients();
		$clientsModel->insert($data);

		$i = explode(",",$liste);
		for ($compt=0; $compt<(count($i)); $compt++) {
			unset($_SESSION[$i[$compt]]);
		}

		// Ajout du client pour les prochaines ventes
		if ($commission != "") {
			$com = str_replace(",",".", $commission);
		} else {
			$com = 0;
		}

		$rows = $this->clientsModel->getVentes($num_vente);
		foreach($rows as $row) {
			if ($row['p_ventes'] == $num_vente) {
				$numclient = $numclient;
			} else {
				$numclient = 'n';
			}

			$this->clientsModel->insetClientEvent($cle, $row['p_ventes'], $numclient, $com);
		}

		$this->_redirect('admin/clients?num_vente='. $num_vente .'&org='. $org);
	}

	public function updateClientAction()
	{
		$num_vente = $this->_getParam('num_vente', 0);
		$num_client = $this->_getParam('num_client', '');
        $org = $this->_getParam('org', 'all');
		$num = $this->_getParam('id', 0);

		$userId = $this->_getParam('userid', '');
		if ($userId != "") {
			$qU = "select p_clients from clients where userid='$userId'";
			$rowU = $this->clientsModel->fecthRowClient($qU);
			$numRow = $this->clientsModel->rowCountClient($qU);
			if ($numRow == 1 && $rowU['p_clients'] != $num) {
				$mgs  = "Ce userid existe déjà dans la DB !";
				$this->_helper->flashMessenger->addMessage($mgs);
				$this->_redirect('admin/clients/edit?num='. $num .'&num_vente='. $num_vente .'&org='. $org);
			}
		}

		$email = $this->_getParam('email', '');
		if ($email != "") {
			$qU = "select p_clients from clients where email='$email'";
			$rowU = $this->clientsModel->fecthRowClient($qU);
			$numRow = $this->clientsModel->rowCountClient($qU);
			if ($numRow == 1 && $rowU['p_clients'] != $num) {
				$mgs  = "Cette adresse e-mail existe déjà dans la DB !";
				$this->_helper->flashMessenger->addMessage($mgs);
				$this->_redirect('admin/clients/edit?num='. $num .'&num_vente='. $num_vente .'&org='. $org);
			}
		}

		// Si on archive le client, on lui retire son n° d'acheteur dans les ventes suivantes
		$archive = $this->_getParam('archive', '');
		if($archive == 1) {
			$this->clientsModel->updateClientVentes($num, $num_vente);
			$num_client = 'n';
		}

		if (!$num_client) { $num_client = 'n'; }
		if ($num_client != 'n') {

			$q = "SELECT clients.p_clients, clients.archive FROM clients
			Left Join clients_ventes ON clients.p_clients = clients_ventes.f_clients
			where deleted = 0 and clients_ventes.num_client='". sprintf("%04s",$num_client) ."' and f_ventes = $num_vente";

			$row = $this->clientsModel->fecthRowClient($q);
			$numRow = $this->clientsModel->rowCountClient($q);

			if ($numRow != 0 && $row['p_clients'] != $num) {
				$mgs  = "Ce n° de client existe déjà !";
				$this->_helper->flashMessenger->addMessage($mgs);
				$this->_redirect('admin/clients/edit?num='. $num .'&num_vente='. $num_vente .'&org='. $org);
			} else {
				$q = "update clients_ventes set num_client = '" . sprintf('%04s',$num_client) . "' where f_clients = $num and f_ventes = $num_vente";
				$this->clientsModel->updateRowClient($q);
			}
		} else {
			$q = "update clients_ventes set num_client = 'n' where f_clients = $num and f_ventes = $num_vente";
			$this->clientsModel->updateRowClient($q);
		}

		$vendeur = $this->_getParam('vendeur', 0);
		$acheteur = $this->_getParam('acheteur', 0);
		$contact = $this->_getParam('contact', 0);
		$nom = addslashes($this->_getParam('nom', ''));
		$co = addslashes($this->_getParam('co', ''));
		$prenom = addslashes($this->_getParam('prenom', ''));
		$adresse = addslashes($this->_getParam('adresse', ''));
		$adresse2 = addslashes($this->_getParam('adresse2', ''));
		$ville = addslashes($this->_getParam('ville', ''));
		$bd = $this->_getParam('bd', 0);
		$obj = $this->_getParam('obj', 0);
		$fg = $this->_getParam('fg', 0);
		$archive = $this->_getParam('archive', 0);

		$identite = $this->_getParam('identite', 0);
		$email = $this->_getParam('email', '');
		$pays = $this->_getParam('pays', '');
		$tel1 = $this->_getParam('tel1', '');
		$tel2 = $this->_getParam('tel2', '');
		$tel3 = $this->_getParam('tel3', '');
		$tel4 = $this->_getParam('tel4', '');
		$banque = $this->_getParam('banque', '');
		$tva = $this->_getParam('tva', '');
		$civilite = $this->_getParam('civilite', '');
		$catoffice = $this->_getParam('catoffice', '');
		$contact_depot = $this->_getParam('contact_depot', '');
		$commission = $this->_getParam('commission', '');
		$cp = $this->_getParam('cp', '');

		$data = array(
			vendeur			=> $vendeur,
			acheteur		=> $acheteur,
			num_identite	=> $identite,
			email			=> $email,
			prenom			=> $prenom,
			nom				=> $nom,
			adresse			=> $adresse,
			adresse2		=> $adresse2,
			cp				=> $cp,
			ville			=> $ville,
			f_pays			=> $pays,
			tel1			=> $tel1,
			tel2			=> $tel2,
			tel3			=> $tel3,
			tel4			=> $tel4,
			compte_banque	=> $banque,
			tva				=> $tva,
			dtcreat			=> date('Y-m-d'),
			hrcreat			=> date('His'),
			co				=> $co,
			f_civilites		=> $civilite,
			contact			=> $contact,
			bd				=> $bd,
			obj				=> $obj,
			fg				=> $fg,
			userid			=> $userId,
			archive			=> $archive,
			catoffice		=> $catoffice,
			contact_depot	=> $contact_depot
		);

		$clientsModel = new Admin_Model_Clients();
		$clientsModel->update($data, 'p_clients = ' . $num);


		$valid = $this->_getParam('valid', '');
		// On vérifie s'il faut valider cet utilisateur
		if (isset($valid) && $valid == 1) {
			//$q = "update clients set dtvalid = '$ladate',hrvalid='$lheure',validated=1,acheteur=1 where p_clients = $_GET[num]";
			$q = "update clients set dtvalid = '". date('Y-m-d') ."',hrvalid='" . date('His') ."',validated=1 where p_clients = $num";
			$this->clientsModel->updateRowClient($q);
			//include("_mail_confirm_validation.php");
		}
			// On vérifie s'il faut retirer la validation de cet utilisateur
		if (isset($valid) && $valid == '19000101') {
			$q = "update clients set dtvalid=null,hrvalid=null,validated=0 where p_clients = $num";
			$this->clientsModel->updateRowClient($q);
		}

		// Ajout dans la table clients_ventes si n° d'acheteur présent ou possède des articles en vente
		// Vérification de la présence d'articles
		$q = "select p_articles from articles where f_clients_deposant = $_GET[num]";
		$numRow = $this->clientsModel->rowCountClient($q);

		if ($_POST[num_client] != 'n' || $numRow > 0) {
			$q = "delete from clients_ventes where f_clients = $num and f_ventes = $num_vente]";
			$this->clientsModel->updateRowClient($q);
			$commission = str_replace(",",".",$commission);
			$q = "insert into clients_ventes (f_clients,f_ventes,num_client,commission) values ($num,$num_vente,'$num_client',$commission)";
			$this->clientsModel->updateRowClient($q);
		}

		// Zone commission
		//echo "com : " .$_POST[commission]."<br>";
		if ($_POST[commission] != "") {
			$_POST[commission] = str_replace(",",".",$_POST[commission]);
			//$q = "update clients set commission=$_POST[commission] where p_clients = $_GET[num]";
			$q_comm = "update clients_ventes set commission = $_POST[commission] where f_clients = $_GET[num] and f_ventes = $_GET[numVente]";
			$r_comm = mysql_query($q_comm) or die ("erreur update : $q_comm<br>".mysql_error());
		}

		// Si on clique sur le bouton sauver, on redirige sut la liste des clients
		if (isset($_POST[sauver])) {
			echo "<script language=\"javascript\">";
			echo "window.location.replace(\"clients.php?numVente=$_GET[numVente]&org=$_GET[org]#$_GET[num]\")";
			echo "</script>";
		}

		// Vérification de l'existence du client, en fonction de la flèche cliquée
		$client=0;
		// Si le client ne porte pas de n°, on doit choisir le client suivant en fonction du tri sur le nom
		if ($_POST[num_client] == "n" || $_POST[num_client] == "") {

			$q = "
			SELECT
			clients_ventes.f_clients,
			clients.nom
			from clients_ventes Inner Join clients ON clients_ventes.f_clients = clients.p_clients
			WHERE clients_ventes.f_ventes = $_GET[numVente]
			and clients.p_clients > 0
			and clients_ventes.num_client = 'n'
			and clients.deleted = 0
			ORDER BY clients.nom ASC
			";
			$r = mysql_query($q) or die ("erreur select : $q<br>".mysql_error());
			$values = array();
			$c = 0;
			while ($row = mysql_fetch_array($r)) {
				$values[$c] =  $row[f_clients];
				$c++;
			}

		} else {
		// Si le client a un n°, on doit choisir le numéro suivant
			$q = "SELECT
			clients_ventes.num_client
			FROM
			clients
			Left Join clients_ventes ON clients.p_clients = clients_ventes.f_clients
			where deleted = 0 and p_clients > 0
			and f_ventes = $_GET[numVente]
			and p_clients = $_GET[num]";
			$r = mysql_query($q) or die ("erreur select : $q<br>".mysql_error());
			$row = mysql_fetch_object($r);

			if (isset($_POST[btn_next_x]) ) {
				$client = $row->num_client + 1;
			}
			if (isset($_POST[btn_prev_x])) {
				$client = $row->num_client - 1;
			}
			if (isset($_POST[btn_next_100_x])) {
				$client = $row->num_client + 100;
			}
			if (isset($_POST[btn_prev_100_x])) {
				$client = $row->num_client - 100;
			}
			if (isset($_POST[btn_search])) {
				$client = $_POST[num_search];
			}

			$q= "SELECT
			clients_ventes.f_clients
			FROM
			clients
			Left Join clients_ventes ON clients.p_clients = clients_ventes.f_clients
			where deleted = 0 and p_clients > 0
			and f_ventes = $_GET[numVente]
			and clients_ventes.num_client = $client";
			$r = mysql_query($q) or die ("erreur select : $q<br>".mysql_error());
			$row = mysql_fetch_object($r);
			$client = $row->f_clients;
		}

		if ($client != 0) {
			//$row = mysql_fetch_object($r);
			echo "<script language=\"javascript\">";
			echo "window.location.replace(\"clients.php?part=edit&num=$client&org=$_GET[org]&numVente=$_GET[numVente]\")";
			echo "</script>";
		} else {
			echo "<p align=\"center\"><span class=\"gras-rouge\">Il n'y a plus de clients !</span></p>\n";
			echo "<p align=\"center\"><a href=\"clients.php?org=$_GET[org]&numVente=$_GET[numVente]\">Retour à la liste des clients</a></p>\n";
		}
	}

    public function deleteAction()
    {
        $num = $this->_getParam('num');
        $num_vente = $this->_getParam('num_vente');
        $page = $this->_getParam('page', 1);
        $org = $this->_getParam('org', 'all');
        $this->clientsModel->removeClient($num, $num_vente);

        $param = '';
        if($page > 1) $param = '&page=' . $page;
        $this->_redirect('admin/clients?num_vente='. $num_vente .'&org='. $org . $param);
    }

	public function searchEmailAction()
	{
		$btnSearch = $this->_getParam('btnSearch', '');
		$org = $this->_getParam('org', 'all');
		$num_vente = $this->_getParam('num_vente', 0);
		$email = $this->_getParam('lemail', '');

		if($btnSearch) {
			$row = $this->clientsModel->getCLientsByEmail($email);

			if($row['p_clients']) {
				$this->_redirect('admin/clients/edit/?id='. $row['p_clients'] .'&num_vente='. $num_vente .'&org='. $org);
			} else {
				$msg = "Cette adresse n'a pas été trouvée !";
				$this->view->msg = $msg;
			}
		}

		$this->view->org = $org;
        $this->view->num_vente = $num_vente;
	}

	public function ficheClientPdfAction()
	{

	}

	public function sendMailAction()
	{
	    echo 'Le mail a été envoyé';
	    exit;
	}

	public function savePdfAction()
	{
	    include_once 'My/Pdf/Mc_Table.php';
	    $model = Mage::getModel('admin/clients');
	    $id = $this->_getParam('id', null);
	    $numVente = $this->_getParam('num_vente');
	    if (!$id) {
	        echo 'Les clients non existe';
	    }

	    $client = $model->getClientForPdf($id, $numVente);
        $row = (object) $client;

	    $pdf = new PDF_MC_Table('P','mm','A4');
	    $pdf->Open();
	    $pdf->SetFont('Arial','',12);
	    $pdf->SetAuthor('Banque Dessinée');
	    $pdf->SetTitle('Fiche client');
	    $pdf->AddPage();
	    $y = $pdf->GetY(15);

	    $compteur = 0;
	    if ($row->civilite != "") {
	        $lenom = $row->civilite . " " . stripslashes($row->prenom) . " " . stripslashes($row->nom);
	    } else {
	        $lenom = stripslashes($row->prenom) . " " . stripslashes($row->nom);
	    }
	    if ($row->co != "") {
	        $lenom .= " c/o " . stripslashes($row->co);
	    }

	    $typeclient = "";
	    if ($row->vendeur == 1) {
	        $typeclient = "Vendeur";
	    }
	    if ($row->acheteur == 1) {
	        $typeclient = "Acheteur";
	    }
	    if ($row->acheteur == 1 && $row->vendeur == 1) {
	        $typeclient = "Vendeur et Acheteur";
	    }

	    // LIGNE 1 : Type Client, N°, Commission
	    $x=$pdf->GetX();
	    $y=$pdf->GetY();
	    $pdf->SetXY($x,$y);
	    $pdf->SetFont('Arial','B',12);
	    $pdf->Cell(30,12,'Type de client :',0,0,'R');
	    $pdf->SetX($x+32);
	    $pdf->SetFont('Arial','',12);
	    $pdf->Cell(30,12,$typeclient,0,0,'L');
	    $pdf->SetX(85);
	    $pdf->SetFont('Arial','B',12);
	    $pdf->Cell(10,12,'N° :',0,0,'R');
	    if ($row->num_client != "n") {
	        $pdf->SetX(95);
	        $pdf->SetFont('Arial','',12);
	        $pdf->Cell(30,12,(int)$row->num_client,0,0,'L');
	    }
	    $pdf->SetX(135);
	    $pdf->SetFont('Arial','B',12);
	    $pdf->Cell(10,12,'Commission :',0,0,'R');
	    $pdf->SetX(147);
	    $pdf->SetFont('Arial','',12);
	    $pdf->Cell(30,12,$row->commission.' %',0,0,'L');

	    // LIGNE 2 : CIVILITE, PRENOM, NOM
	    $y=$pdf->GetY();
	    $pdf->SetXY(13,$y+10);
	    $pdf->SetFont('Arial','B',12);
	    $pdf->Cell(30,12,'Nom :',0,0,'R');
	    $pdf->SetX($x+32);
	    $pdf->SetFont('Arial','',12);
	    $pdf->Cell(120,12,$lenom,0,0,'L');

	    // LIGNE 3 : ADRESSE
	    $y=$pdf->GetY();
	    $pdf->SetXY(13,$y+10);
	    $pdf->SetFont('Arial','B',12);
	    $pdf->Cell(30,12,'Adresse :',0,0,'R');
	    $pdf->SetX($x+32);
	    $pdf->SetFont('Arial','',12);
	    $pdf->Cell(120,12,stripslashes($row->adresse),0,0,'L');
	    if ($row->adresse2 != "") {
	        $y=$pdf->GetY();
	        $pdf->SetXY($x+32,$y+6);
	        $pdf->SetFont('Arial','',12);
	        $pdf->Cell(120,12,stripslashes($row->adresse2),0,0,'L');
	    }

	    // LIGNE 3 : CP + LOCALITE + PAYS
	    $y=$pdf->GetY();
	    $pdf->SetXY(13,$y+10);
	    $pdf->SetFont('Arial','B',12);
	    $pdf->Cell(30,12,'Localité :',0,0,'R');
	    $pdf->SetX($x+32);
	    $pdf->SetFont('Arial','',12);
	    $pdf->Cell(120,12,$row->cp . " " . stripslashes($row->ville),0,0,'L');
	    if ($row->pays != "Belgique") {
	        $pdf->SetX(135);
	        $pdf->SetFont('Arial','B',12);
	        $pdf->Cell(10,12,'Pays :',0,0,'R');
	        $pdf->SetX(147);
	        $pdf->SetFont('Arial','',12);
	        $pdf->Cell(30,12,stripslashes($row->pays),0,0,'L');
	    }

	    // LIGNE 4 : TELEPHONES 1 & 2
	    $y=$pdf->GetY();
	    $pdf->SetXY(13,$y+10);
	    $pdf->SetFont('Arial','B',12);
	    $pdf->Cell(30,12,'Tél 1 :',0,0,'R');
	    $pdf->SetX($x+32);
	    $pdf->SetFont('Arial','',12);
	    $pdf->Cell(120,12,$row->tel1,0,0,'L');
	    if ($row->tel2 != "") {
	        $pdf->SetX(135);
	        $pdf->SetFont('Arial','B',12);
	        $pdf->Cell(10,12,'Tél 2 :',0,0,'R');
	        $pdf->SetX(147);
	        $pdf->SetFont('Arial','',12);
	        $pdf->Cell(30,12,$row->tel2,0,0,'L');
	    }

	    // LIGNE 5 : TELEPHONES 3 & 4
	    if ($row->tel3 != "" || $row->tel4 != "") {
	        $y=$pdf->GetY();
	        $pdf->SetXY(13,$y+10);
	        $pdf->SetFont('Arial','B',12);
	        $pdf->Cell(30,12,'Tél 3 :',0,0,'R');
	        $pdf->SetX($x+32);
	        $pdf->SetFont('Arial','',12);
	        $pdf->Cell(120,12,$row->tel3,0,0,'L');
	        if ($row->tel4 != "") {
	            $pdf->SetX(135);
	            $pdf->SetFont('Arial','B',12);
	            $pdf->Cell(10,12,'Tél 4 :',0,0,'R');
	            $pdf->SetX(147);
	            $pdf->SetFont('Arial','',12);
	            $pdf->Cell(30,12,$row->tel4,0,0,'L');
	        }
	    }

	    // LIGNE 6 : CP + LOCALITE + PAYS
	    $y=$pdf->GetY();
	    $pdf->SetXY(13,$y+10);
	    $pdf->SetFont('Arial','B',12);
	    $pdf->Cell(30,12,'N° compte :',0,0,'R');
	    $pdf->SetX($x+32);
	    $pdf->SetFont('Arial','',12);
	    $pdf->Cell(120,12,$row->compte_banque,0,'L');
	    $pdf->SetX(135);
	    $pdf->SetFont('Arial','B',12);
	    $pdf->Cell(10,12,'N° identité :',0,0,'R');
	    $pdf->SetX(147);
	    $pdf->SetFont('Arial','',12);
	    $pdf->Cell(30,12,$row->num_identite,0,0,'L');

	    // LIGNE 7 : CP + LOCALITE + PAYS
	    $y=$pdf->GetY();
	    $pdf->SetXY(13,$y+10);
	    $pdf->SetFont('Arial','B',12);
	    $pdf->Cell(30,12,'E-Mail :',0,0,'R');
	    $pdf->SetX($x+32);
	    $pdf->SetFont('Arial','',12);
	    $pdf->Cell(120,12,$row->email,0,0,'L');
	    if ($row->tva != "") {
	        $pdf->SetX(135);
	        $pdf->SetFont('Arial','B',12);
	        $pdf->Cell(10,12,'N° TVA :',0,0,'R');
	        $pdf->SetX(147);
	        $pdf->SetFont('Arial','',12);
	        $pdf->Cell(30,12,$row->tva,0,0,'L');
	    }

	    if (!$this->_getParam('id')) {
	        $y=$pdf->GetY();
	        $y=$y+8;
	        $pdf->SetLineWidth(0.7);
	        $pdf->Line($x,$y+5,$x+170,$y+5);
	        $pdf->SetLineWidth(0.2);
	        $x=$pdf->GetX();
	        $y=$pdf->GetY();
	        $pdf->SetXY(13,$y+15);

	        $compteur++;

	        if ($compteur % 3 == 0) {
	            $pdf->AddPage();
	        }

	    }
	    $pdf->Output();
	    exit;
	}
}

